﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Basic4Net.Utility.Common;
using Basic4Net.OAWeb.Base;

namespace Basic4Net.OAWeb.Module_Base
{
    public partial class TeacherType : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                typebind();
            }
        }

        private void typebind()
        {
            this.rpt_TeacherType.DataSource = (new BusinessRules.TeacherType()).ListAll();
            this.rpt_TeacherType.DataBind();
        }

        protected void rpt_TeacherType_OnItemCommand(object source, RepeaterCommandEventArgs e)
        {
            string msg = string.Empty;
            BusinessRules.TeacherType bll = new BusinessRules.TeacherType();
            DropDownList ddl = (DropDownList)e.Item.FindControl("ddl_FType");
            switch (e.CommandName)
            {
                case "Change":
                    TextBox txt = (TextBox)e.Item.FindControl("txt_Name");
                    Entities.t_TeacherType model = new Entities.t_TeacherType();
                    model.RID = int.Parse(e.CommandArgument.ToString());
                    model.TypeName = txt.Text;
                    model.FType = int.Parse(ddl.SelectedValue);
                    model.SchoolMark = "School";
                    bll.Update(model,ref msg);
                    break;
                case "Del":
                    bll.Delete(int.Parse(e.CommandArgument.ToString()),ref msg);
                    typebind();
                    break;
            }
        }

        protected static string GetFTypeStr(string FType)
        {
            switch (int.Parse(FType))
            {
                case 1:
                    return "在职中高层核算方式";
                case 2:
                    return "在职普通教工核算方式";
                case 3:
                    return "临聘教工核算方式";
                default :
                    return "未知核算类型";
            }
        }

        protected void rpt_TeacherType_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            DropDownList ddl = (DropDownList)e.Item.FindControl("ddl_FType");
            HiddenField hdf = (HiddenField)e.Item.FindControl("hdf_FType");
            if (ddl != null)
            {
                DataTable dt = new DataTable();
                Common.AddRow(dt, 1, "在职中高层核算方式");
                Common.AddRow(dt, 2, "在职普通教工核算方式");
                Common.AddRow(dt, 3, "临聘教工核算方式");
                ddl.DataValueField = "id";
                ddl.DataTextField = "name";
                ddl.DataSource = dt;
                ddl.DataBind();
                ddl.SelectedValue = hdf.Value;
            }
        }

        [System.Web.Services.WebMethod]
        protected void btnBind_Click(object sender, EventArgs e)
        {
            string msg = string.Empty;
            Entities.t_TeacherType model = new Entities.t_TeacherType();
            model.TypeName = this.txt_TypeName.Text;
            if (this.rbn_type1.Checked)
                model.FType = 1;
            if (this.rbn_type2.Checked)
                model.FType = 2;
            if (this.rbn_type3.Checked)
                model.FType = 3;
            model.SchoolMark = SchoolMark;
            (new BusinessRules.TeacherType()).Add(model, ref msg);
            typebind();
        }
    }
}